package com.bgs.eat.commodity.mapper;

import com.bgs.eat.commodity.entity.CommodityEntity;
import com.bgs.eat.config.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface CommodityMapper extends BaseMapper<CommodityEntity> {

    /**
    * @Description 商品总数 减 1
    * @Author lzy
    * @Date 2022/10/27 9:02
    * @Return java.lang.Integer
    * @param id
    */
    @Update("update commodity set sum = sum - 1 where id = #{id}")
    Integer commoditySubtractSum(Integer id);


    /**
    * @Description 商品总数 加 一
    * @Author lzy
    * @Date 2022/10/27 9:02
    * @Return java.lang.Integer
    * @param id
    */
    @Update("update commodity set sum = sum + 1 where id = #{id}")
    Integer commodityAddSum(Integer id);

    /**
    * @Description 根据商品id查询商品剩余数量
    * @Author lzy
    * @Date 2022/10/27 11:05
    * @Return java.lang.Integer
    * @param id
    */
    @Select("select sum from commodity where id = #{id}")
    Integer selectCommoditySumById(Integer id);

    @Select("select sum from commodity where id = #{id}")
    Integer checkCommoditySum(Integer id);
}
